home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************
- #
- # init.c
- #
- # basic initialization code.
- #
- # Author(s): Michael Marinkovich
- # Apple Developer Technical Support
- # marink@apple.com
- #
- # Modification History:
- #
- # 4/3/96 MWM Initial coding
- #
- # Copyright © 1992-96 Apple Computer, Inc., All Rights Reserved
- #
- #
- # You may incorporate this sample code into your applications without
- # restriction, though the sample code has been provided "AS IS" and the
- # responsibility for its operation is 100% yours. However, what you are
- # not permitted to do is to redistribute the source as "DSC Sample Code"
- # after having made changes. If you're going to re-distribute the source,
- # we require that you make it clear in the source that the code was
- # descended from Apple Sample Code, but that you've made changes.
- #
- *************************************************************************************/
-
-
- #include <AppleEvents.h>
- #include <Displays.h>
- #include <Events.h>
- #include <Fonts.h>
- #include <Gestalt.h>
- #include <Menus.h>
- #include <OSUtils.h>
-
- #include "App.h"
- #include "Proto.h"
-
-
- //----------------------------------------------------------------------
- // Globals
- //----------------------------------------------------------------------
-
- extern Boolean gHasDMTwo;
- extern Boolean gHasDrag;
- extern Boolean gInBackground;
- extern short gWindCount;
-
-
- //----------------------------------------------------------------------
- //
- // Initialize - the main entry point for the initialization
- //
- //
- //----------------------------------------------------------------------
-
- OSErr Initialize(void)
- {
- OSErr err = noErr;
-
-
- ToolBoxInit();
- CheckEnvironment();
- err = InitApp();
-
- return err;
- }
-
-
- //----------------------------------------------------------------------
- //
- // ToolBoxInit - initialization all the needed managers
- //
- //
- //----------------------------------------------------------------------
-
- void ToolBoxInit(void)
- {
-
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
-
- FlushEvents(everyEvent, 0);
-
- }
-
-
- //----------------------------------------------------------------------
- //
- // CheckEnvironment - make sure we can run with current sys and managers.
- // Also initialize globals - have drag & drop
- //
- //----------------------------------------------------------------------
-
- void CheckEnvironment(void)
- {
- OSErr err;
- long response;
-
-
- // check to see if the Display Manager is present. If it is
- // then we have a PowerMac or System 7.5.
- err = Gestalt(gestaltDisplayMgrAttr, &response);
-
- if (err != noErr || ((response & (1 << gestaltDisplayMgrPresent)) == 0))
- HandleAlert(kNeedsDisplayManager);
-
- // check for Display Manager 2.0
- else {
- Gestalt(gestaltDisplayMgrVers, (long*)&response);
- gHasDMTwo = (response >= 0x00020000);
- }
-
- }
-
-
- //----------------------------------------------------------------------
- //
- // InitApp - initialization all the application specific stuff
- //
- //
- //----------------------------------------------------------------------
-
- OSErr InitApp(void)
- {
- OSErr err;
-
- // init AppleEvents
- err = AEInit();
- MenuSetup();
-
- // we have DM 2.0 so install
- // world changed notification proc
- if (gHasDMTwo)
- err = InstallDMNotification();
-
- // we have DM 1.0 so install AppleEvent Notification
- else
- err = InstallAEDMNotification();
-
- // init any globals
- gWindCount = 1;
-
- return err;
- }
-
-
- //----------------------------------------------------------------------
- //
- // MenuSetup -
- //
- //
- //----------------------------------------------------------------------
-
- void MenuSetup(void)
- {
- Handle menu;
-
-
- menu = GetNewMBar(rMBarID); // get our menus from resource
- SetMenuBar(menu);
- DisposeHandle(menu);
- AddResMenu(GetMHandle(mApple ), 'DRVR'); // add apple menu items
-
- DrawMenuBar();
-
-
- }
-